using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DICE_GS;

public class GameReadySceneManager : MonoBehaviour {
	public UISprite[] skillIcon;
	public UILabel[] itemLabel;
	public GameObject[] cardObject;
	
	public UILabel userGoldLabel;
	public UILabel userDiamondLabel;
	public UILabel userStaminaLabel;
	
	public UILabel singleGameModeLabel;
	public UILabel multiGameModeLabel;
	
	public GameObject directEnterButton;
	public GameObject makeRoomButton;
	public GameObject singleGameStartButton;
	
	public GameObject SelectFriendWindowObject;
	
	public GameObject myPartyTag;
	public UILabel noSettingDeckLabel;
	
	// Use this for initialization
	void Start () {
		if( CSceneManager.isSingleGame )
		{
			singleGameModeLabel.gameObject.SetActive(true);
			directEnterButton.SetActive(false);
			makeRoomButton.SetActive(false);
			singleGameStartButton.SetActive(true);
			if( MyInfo.Instance.currentDeckInfo.currentActivateCardCount == 0 )
			{
				singleGameStartButton.GetComponentInChildren<UISprite>().spriteName = "Copy of UI_btn01_grey";
				singleGameStartButton.collider.enabled = false;
				myPartyTag.SetActive(false);
				noSettingDeckLabel.gameObject.SetActive(true);
			}
		}
		else
		{
			multiGameModeLabel.gameObject.SetActive(true);
			directEnterButton.SetActive(true);
			makeRoomButton.SetActive(true);
			singleGameStartButton.SetActive(false);
			if( MyInfo.Instance.currentDeckInfo.currentActivateCardCount == 0 )
			{
				directEnterButton.GetComponentInChildren<UISprite>().spriteName = "Copy of UI_btn01_grey";
				directEnterButton.collider.enabled = false;
				makeRoomButton.GetComponentInChildren<UISprite>().spriteName = "Copy of UI_btn01_grey";
				makeRoomButton.collider.enabled = false;
				myPartyTag.SetActive(false);
				noSettingDeckLabel.gameObject.SetActive(true);
			}
		}	
			 
		if( MyInfo.Instance.currentDeckInfo.currentActivateCardCount > 0 )
		{
			myPartyTag.SetActive(true);
			noSettingDeckLabel.gameObject.SetActive(false);
		}
		
		int cardIndex = 0;
		DeckInfo deckInfo = MyInfo.Instance.MyDeckMap[MyInfo.Instance.MyCurrentDeck];
		foreach(KeyValuePair<int, UnitInfo> pair in deckInfo.SlotMap)
		{
			if( pair.Value.UnitDBID != 0 )
			{
				cardObject[cardIndex].GetComponent<MyUnitCard>().SetCardInfo(cardIndex, pair.Value);
				cardObject[cardIndex].SetActive(true);
				cardObject[cardIndex++].collider.enabled = false;
			}
		}
		for(int i=cardIndex; i<5; i++)
		{
			cardObject[i].SetActive(false);
		}
		
		skillIcon[0].spriteName = deckInfo.skill1_IconName;
		skillIcon[1].spriteName = deckInfo.skill2_IconName;
		
		itemLabel[0].text = "x" + MyInfo.Instance.HPPotion;
		itemLabel[1].text = "x" + MyInfo.Instance.ResurrectPotion;
		
		userGoldLabel.text = MyInfo.Instance.Money.ToString();
		userDiamondLabel.text = MyInfo.Instance.Diamond.ToString();
		userStaminaLabel.text = MyInfo.Instance.Stamina.ToString();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnClickSelectFriendWindowCloseButton()
	{
		if(SelectFriendWindowObject.activeSelf)
			SelectFriendWindowObject.SetActive(false);
	}
	
	void OnClickGotoSingleGameAlone()
	{
		CSceneManager.manager.GoToEnterroomScene(MainSceneManager.selectedSingleMapName, "");
	}
}
